package com.example.controller;



import com.example.domain.Charge;
import com.example.domain.Examination;
import com.example.service.ChargeService;
import com.example.utils.AjaxResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.jnlp.IntegrationService;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import static com.example.utils.AjaxResult.successData;

@RestController
@RequestMapping("/root")
public class ChargeController {
    @Autowired
    private ChargeService chargeService;

    @RequestMapping("/charge")
    public AjaxResult Examination(@RequestParam(defaultValue = "1", value = "page") Integer pageNum,
                                  @RequestParam(defaultValue = "10", value = "limit") Integer pageSize,
                                  @RequestParam(defaultValue = "" , value = "charge") String usr, HttpServletRequest request
    ){
        int patient_id =(int) request.getSession().getAttribute("patient_id");
        HashMap<String, Object> map = new HashMap<>();
        PageHelper.startPage(pageNum,pageSize);
        Charge charge=new Charge(chargeService.get_total_medicine_price(patient_id),
                                 chargeService.get_total_check_price(patient_id),
                      chargeService.get_total_medicine_price(patient_id)+chargeService.get_total_check_price(patient_id)
        );
        if (usr == null || usr.equals("")) {
            map.put("usr","");
            List<Charge> chargeList = new ArrayList<>();
            chargeList.add(charge);
            PageInfo<Charge> page = new PageInfo<>(chargeList);
            return successData(page.getTotal(), chargeList);
        }
        map.put("usr",usr);
        List<Charge> chargeList = new ArrayList<>();
        chargeList.add(charge);
        PageInfo<Charge> page = new PageInfo<>(chargeList);
        return successData(page.getTotal(), chargeList);
    }

}
